'''
建学生类, 包含姓名,学号,性别,年份. 让用户输入学生信息,将多个学生存入列表,并按年份排序
2021-8-14 Nasa
'''


class Stu:
    def __init__(self, name, xuehao, xingbie, year):
        self.name = name
        self.xuehao = xuehao
        self.xingbie = xingbie
        self.year = year

    def __repr__(self):
        return f'name:{self.name},xueuao:{self.xuehao},xingbie:{self.xingbie},year:{self.year}'


if __name__ == '__main__':
    def main():
        stulist = []
        while True:
            trfa = input('是(y)否(n)添加学生?')
            if trfa == '是' or trfa == 'y':
                xm = input('请输入学生姓名:')
                xh = input('请输入学生学号:')
                xb = input('请输入学生性别:')
                nf = input('请输入学生出生年份:')
                tstu = Stu(xm, xh, xb, nf)
                stulist.append(tstu)

            else:
                break
        stulist.sort(key=lambda x: x.year)
        print(stulist)

main()
